package Management.Source;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Properties;

import javax.swing.Icon;
import javax.swing.ImageIcon;

public class Source {
	public ArrayList<File> sourceList;
	//initial
	private Properties p1 = new Properties();
	private Properties p = new Properties();
	private FileInputStream fis1;
	private FileInputStream fis2;
	private String sourcePath = "./property/sources";
	public File optionProperties = new File(sourcePath + "/Option.properties");
	
	//JArrorwPanel
	public String back;
	public Icon backIcon;
	public String forward;
	public Icon forwardIcon;
	public String rename;
	public Icon renameIcon;
	
	//JTable
	public String ruled;
	public String name;
	public String type;
	public String time;
	public String size;
	
	//JRenamePanel
	public String renameFrameName;
	public Icon renameFrameIcon;
	public String oldName;
	public String newName;
	public String ok;
	public Icon okIcon;
	public String cancel;
	public Icon cancelIcon;
	
	//MainUIFrame
	public String mainFrame;
	public Icon mainFrameIcon;
	
	//JMenuBar
	public String file;
	public String option;
	public Icon optionIcon;
	public String about;
	public Icon aboutIcon;
	public String exit;
	public Icon exitIcon;
	
	//JPopupMenu
	public String open;
	public Icon openIcon;
	public String reName;
	public String new1;
	public String newFile;
	public String newDirectory;
	public String copy;
	public Icon copyIcon;
	public String paste;
	public Icon pasteIcon;
	public String cut;
	public Icon cutIcon;
	public String delete;
	public Icon deleteIcon;
	
	public Source() {
		//get the language Package;
		sourceList = new ArrayList<File> ();
		File[] sources = new File("./property/sources").listFiles();
		for (File f: sources) {
			if (f.getName().equals("Default.language")) {
				sourceList.add(0, f);
			}
			else if (f.getName().endsWith(".language")) {
				sourceList.add(f);
				System.out.println("language Package:" + f);
			}
		}
		
		//initial;
		try {
			fis1 = new FileInputStream(optionProperties);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		try {
			p1.load(fis1);
		} catch (IOException e) {
			e.printStackTrace();
		}
		String languagePackNumber = p1.getProperty("languagePackNumber");
		System.out.println(new Byte(languagePackNumber).intValue());
		try {
			fis2 = new FileInputStream(sourceList.get(new Byte(languagePackNumber).intValue()));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		try {
			p.load(fis2);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
		//JArrorwPanel
		back = p.getProperty("back");
		backIcon = new ImageIcon(sourcePath + File.separator + p.getProperty("backIcon"));
		forward = p.getProperty("forward");
		forwardIcon = new ImageIcon(sourcePath + File.separator +p.getProperty("forwardIcon"));
		rename = p.getProperty("rename");
		renameIcon = new ImageIcon(sourcePath + File.separator + p.getProperty("renameIcon"));
		
		//JTable
		ruled = p.getProperty("ruled");
		type = p.getProperty("type");
		name = p.getProperty("name");
		time = p.getProperty("time");
		size = p.getProperty("size");
		
		//JRenamePanel
		oldName = p.getProperty("oldName");
		newName = p.getProperty("newName");
		ok = p.getProperty("ok");
		okIcon = new ImageIcon(sourcePath + File.separator + p.getProperty("okIcon"));
		cancel = p.getProperty("cancel");
		cancelIcon = new ImageIcon(sourcePath + File.separator + p.getProperty("cancelIcon")); 
		renameFrameName = p.getProperty("renameFrameName");
		renameFrameIcon = renameIcon;
		
		//MainUIFrame
		mainFrame = p.getProperty("mainFrame");
		mainFrameIcon = new ImageIcon(sourcePath + File.separator + p.getProperty("mainFrameIcon"));
		
		//JMenuBar
		file = p.getProperty("file");
		option = p.getProperty("option");
		optionIcon = new ImageIcon(sourcePath + File.separator + p.getProperty("optionIcon"));
		about = p.getProperty("about");
		aboutIcon = new ImageIcon(sourcePath + File.separator + p.getProperty("aboutIcon"));
		exit = p.getProperty("exit");
		exitIcon = new ImageIcon(sourcePath + File.separator + p.getProperty("exitIcon"));
		
		//JPopupMenu
		open = p.getProperty("open");
		openIcon = new ImageIcon(sourcePath + File.separator + p.getProperty("openIcon"));
		reName = p.getProperty("reName");
		new1 = p.getProperty("new1");
		newFile = p.getProperty("newFile");
		newDirectory = p.getProperty("newDirectory");
//		newFileIcon = new ImageIcon(sourcePath + File.separator + p.getProperty("newFileIcon"));
		copy = p.getProperty("copy");
		copyIcon = new ImageIcon(sourcePath + File.separator + p.getProperty("copyIcon"));
		paste = p.getProperty("paste");
		pasteIcon = new ImageIcon(sourcePath + File.separator + p.getProperty("pasteIcon"));
		cut = p.getProperty("cut");
		cutIcon = new ImageIcon(sourcePath + File.separator + p.getProperty("cutIcon"));
		delete = p.getProperty("delete"); 
		deleteIcon = new ImageIcon(sourcePath + File.separator + p.getProperty("deleteIcon"));
	}
	
//	public static void main(String[] args) {
//		new Source();
//	}
}
